package com.creating.mict.common;


import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class Sax extends DefaultHandler
{

    java.util.Stack tags = new java.util.Stack();

    public Sax()
    {

        super();
    }

    /**
     * 
     * @param fileName
     * @author bdk197431
     * @date 2010-5-12 ����09:20:04
     */
    public static void doRead(String fileName)
    {

        long lasting = System.currentTimeMillis();
        try
        {

            SAXParserFactory sf = SAXParserFactory.newInstance();

            SAXParser sp = sf.newSAXParser();

            Sax reader = new Sax();

            sp.parse(new InputSource(fileName), reader);

        } catch ( Exception e )
        {

            e.printStackTrace();

        }

        System.out.println("Sax ����ʱ�䣺" + fileName + ":" + (System.currentTimeMillis() - lasting) / 1000.0 + "��");
    }

    /**
     * characters
     */
    public void characters(char ch[], int start, int length) throws SAXException
    {

        String tag = (String) tags.peek();

        /*
         * if (tag.equals("NO")) {
         * 
         * System.out.print("���ƺ��룺" + new String(ch, start, length)); } if
         * (tag.equals("ADDR")) {
         * 
         * System.out.println("��ַ:" + new String(ch, start, length)); }
         */
    }

    /**
     * startElement
     */
    public void startElement(String uri, String localName, String qName, Attributes attrs)
    {

        tags.push(qName);
    }

    public static void main(String[] args)
    {
        String fileName = "E:\\jc20130203.xml";
        doRead(fileName);
    }
}
